using System;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;

using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace UIProcessActivities
{
    public class FindFormResourceDesigner : ActivityDesigner
    {
        FindFormResource parentActivity;

        protected override void Initialize(Activity activity)
        {
            base.Initialize(activity);
            parentActivity = (FindFormResource)activity;
        }

        protected override Size OnLayoutSize(ActivityDesignerLayoutEventArgs e)
        {
            return new Size(100, 50);
        }

        protected override void OnPaint(ActivityDesignerPaintEventArgs e)
        {
            Rectangle frameRect = new Rectangle(this.Location.X, this.Location.Y, this.Size.Width - 5, this.Size.Height - 5);
            Rectangle shadowRect = new Rectangle(frameRect.X + 5, frameRect.Y + 5, frameRect.Width, frameRect.Height);

            Brush frameBrush = new LinearGradientBrush(frameRect, Color.DarkBlue, Color.LightBlue, 45);

            e.Graphics.FillPath(Brushes.LightGray, RoundedRect(shadowRect));
            e.Graphics.FillPath(frameBrush, RoundedRect(frameRect));
            e.Graphics.DrawString(Activity.QualifiedName, new Font("Segoe UI", 9), Brushes.White, frameRect);
        }

        private GraphicsPath RoundedRect(Rectangle frame)
        {
            GraphicsPath path = new GraphicsPath();
            int radius = 7;
            int diameter = radius * 2;

            Rectangle arc = new Rectangle(frame.Left, frame.Top, diameter, diameter);

            path.AddArc(arc, 180, 90);

            arc.X = frame.Right - diameter;
            path.AddArc(arc, 270, 90);

            arc.Y = frame.Bottom - diameter;
            path.AddArc(arc, 0, 90);

            arc.X = frame.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();

            return path;
        }

    }
}
